package com.burgeon.backend.Rest.store;
/**
 * 获取门店map
 *
 */

import com.burgeon.backend.Rest.base.RESTBase;
import com.burgeon.backend.entity.Store;
import org.json.JSONArray;
import org.springframework.util.MultiValueMap;

import java.util.ArrayList;
import java.util.HashMap;

public class GetStoreMap extends RESTBase {

    private String ip;
    private String account;
    private String password;

    public GetStoreMap(String ip, String account, String password) {
        this.ip = ip;
        this.account = account;
        this.password = password;
    }

    /**
     * 发送并接收字符创
     */

    public String getData(String id) throws Exception {
        String url = "http://" + ip + "/servlets/binserv/Rest";

        String str = RESULT(Data(id), url);
        System.err.println(str);
        String code = new JSONArray(str).getJSONObject(0).getString("code");
        if (!"0".equals(code)) {
            throw new Exception();
        }

        JSONArray jsonArray = new JSONArray(str).getJSONObject(0).getJSONArray("rows");


        return jsonArray.getJSONArray(0).getString(0);
    }

    private MultiValueMap Data(String id) {
        HashMap params = new HashMap();
        ArrayList columns = new ArrayList();//查询字段
        columns.add("MAP");

        params.put("columns", columns);
        params.put("table", "C_STORE");//表名

        HashMap paramss = new HashMap();
        String ac = "'=" + id + "'";
        paramss.put("column", "ID");
        paramss.put("condition", ac);
        params.put("params", paramss);


        return DATA("Query", params, account, password);
    }

    public static void main(String[] args) {
        GetStoreMap g = new GetStoreMap("59.110.28.94:90", "nea@burgeon.com.cn", "burgeon55321");
        try {
            System.err.println(g.getData("3480"));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
